﻿CREATE procedure EndAllConversationsWithCleanup
as
begin
	declare conversations cursor local for
	select distinct conversation_handle from sys.conversation_endpoints
	--where not (state='CD' and is_initiator=0)

	declare @ConversationHandle uniqueidentifier
	declare @count int
	set @count = 0

	open conversations
	fetch next from conversations into @ConversationHandle

	while @@fetch_status = 0
	begin
	  set @count = @count + 1
	  end conversation @ConversationHandle with cleanup;
	fetch next from conversations into @ConversationHandle
	end
	close conversations
	deallocate conversations
	select @count conversations_ended
end


